package com.medical.admin.reserve.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.medical.admin.cost.entity.Department;
import com.medical.admin.reserve.common.dto.AppointmentRegisterRequest;
import com.medical.admin.reserve.common.dto.SubscribeDto;
import com.medical.admin.reserve.service.SubscribeService;
import com.qf.medical.response.ResponseCode;
import com.qf.medical.response.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/*
 * @Date : 2024/4/29 下午4:53
 * @Created by Lang
 * @ProjectName : medical-appointment-registration
 */
@RestController
@Api(tags = "预约管理")
@RequestMapping("/reserve")
public class SubscribeController {

    @Resource
    private SubscribeService subscribeService;

    @PostMapping("/add")
    @ApiOperation(value = "提交挂号信息")
    public ResponseEntity<String> addSubscribe(@RequestBody SubscribeDto subscribeDto) {
        Integer res = subscribeService.addSubscribe(subscribeDto);
        if (res > 0) {
            return ResponseEntity.success(ResponseCode.SUBSCRIBE_ADD_SUCCESS.getMsg());
        }
        return ResponseEntity.error(ResponseCode.SUBSCRIBE_ADD_ERROR);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "查看预约挂号详情")
    public ResponseEntity<SubscribeDto> getSubscribe(@RequestParam("subscribeId") Long subscribeId) {
        return ResponseEntity.success(subscribeService.detail(subscribeId));
    }

    @PostMapping("/updateRemark")
    @ApiOperation(value = "修改预约挂号备注")
    public ResponseEntity<String> updateRemark(@RequestParam("subscribeId") Long subscribeId, @RequestParam("subscribeRemark") String remark) {
        Integer res = subscribeService.updateRemarkById(subscribeId, remark);
        if (res > 0) {
            return ResponseEntity.success(ResponseCode.SUBSCRIBE_REMARK_UPDATE_SUCCESS.getMsg());
        }
        return ResponseEntity.error(ResponseCode.SUBSCRIBE_REMARK_UPDATE_ERROR);
    }

    @PutMapping("/del")
    @ApiOperation(value = "根据id删除预约挂号")
    public ResponseEntity<String> delSubscribe(@RequestParam("subscribeId") Long subscribeId) {
        Integer res = subscribeService.delById(subscribeId);
        if (res > 0) {
            return ResponseEntity.success(ResponseCode.SUBSCRIBE_DEL_SUCCESS.getMsg());
        }
        return ResponseEntity.error(ResponseCode.SUBSCRIBE_DEL_SUCCESS);
    }

    @GetMapping("/list")
    @ApiOperation(value = "分页查询预约挂号列表")
    public ResponseEntity<IPage<SubscribeDto>> listSubscribe
            (@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
             @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
             AppointmentRegisterRequest appointmentRegisterRequest) {
        return ResponseEntity.success(subscribeService.list(pageNum,pageSize,appointmentRegisterRequest));
    }


}
